package web.mb;

import java.io.Serializable;

import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;


import metier.entities.Client;
import metier.entities.Employe;
import metier.entities.Utilisateur;
import metier.sess.IUtilisateurLocal;




@ManagedBean
@SessionScoped
public class LoginMB implements Serializable{
	
	private Utilisateur user=new Utilisateur();
	
	@EJB
	private IUtilisateurLocal metier;
	
	//client transporteur ou expéditeur
	private Client client=new Client();
	private Employe employe;
	 
	private  boolean  isLong=false;
	
	private  boolean  remember;
	
	
	
	public boolean isRemember() {
		return remember;
	}



	public void setRemember(boolean remember) {
		this.remember = remember;
	}



	public boolean getLong() {
		return isLong;
	}



	public void setLong(boolean isLong) {
		this.isLong = isLong;
	}



	public Client getClient() {
		return client;
	}



	public void setClient(Client client) {
		this.client = client;
	}



	public Employe getEmploye() {
		return employe;
	}



	public void setEmploye(Employe employe) {
		this.employe = employe;
	}



	private String route; 
	   
	    public Utilisateur getUser() {
		return user;
	}



	public void setUser(Utilisateur user) {
		this.user = user;
	}



		public String loginClient() {
	       
	
	    
	        if((client.getPassword().compareTo("")!=0) && (client.getUsername().compareTo("")!=0) && (client.getCID()!=null) )
	        {
	        	 
	        	 Client c=(Client)metier.getUtilisateurUserName(client);
	        	 if(c==null)
	        	 {
	        		 isLong=false;
	        		 
	        	     FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Invalid login or password"));
	        	     
	 	           
	        	 }
	        	 else
	        	 {
	        		 isLong=true;
	        		 return "/frontOffice/welcome.xhtml";
	        	 }
	        	 
	        	
	        }
	        else
	        {
	        	 FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "all fields are required"));
	        }
	      
	        
	        return "gh";
	    }   
	
}
